#pragma once
#include "RBTree.h"

namespace ns_set
{
	template<class K>
	class MySet
	{
	public:
		struct KeyOfPair
		{
			const K& operator()(const K& k)
			{
				return k;
			}
		};


		typedef typename RBTree<K, K, KeyOfPair>::iterator iterator;
	public:
		pair<iterator, bool> insert(const K& k)
		{
			return _t.Insert(k);
		}


		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		iterator find(const K& key)
		{
			return _t.Find(key);
		}
	private:
		RBTree<K, K, KeyOfPair> _t;
	};

	void test_set()
	{
		MySet<int> s;
		s.insert(1);
		s.insert(3);
		s.insert(2);
		s.insert(6);
		s.insert(7);

		MySet<int>::iterator it = s.begin();
		while (it != s.end())
		{
			cout << *it << " ";
			++it; 
		}
		cout << endl;
		/*auto pos = s.find(3);
		if (pos != s.end())
		{
			cout << *pos << endl;
		}*/

		MySet<int> copy(s);
		for (auto e : copy)
		{
			cout << e << " ";
		}
		cout << endl;


		MySet<int> s1;
		s1 = s;
		for (auto& e : s1)
		{
			cout << e << " ";
		}
		cout << endl;

	}
}